<?php
/**
 * Copyright 2013 Marek Kaszewski
 *
 * This file is part of the JHUB1 Online Community Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Jhub1_Common\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use InvalidArgumentException;
use Jhub1_Common\Model\SettingsObjects\AgentRemoteConfigurationObject;
use Jhub1_Common\Model\SettingsObjects\DateTimeObject;
use Jhub1_Common\Entity\Agents;

/** @ORM\MappedSuperclass */
abstract class EAVBase
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="id", nullable=false);
     * @ORM\GeneratedValue(strategy="AUTO")
     * @var integer
     */
    private $id;

    /**
     * @ORM\Column(type="string", name="name", length=255, nullable=false);
     * @var string
     */
    private $name;

    /**
     * @ORM\Column(type="string", name="att_string", length=255, nullable=true);
     * @var string
     */
    private $string;

    /**
     * @ORM\Column(type="text", name="att_text", nullable=true);
     * @var string
     */
    private $text;

    /**
     * @ORM\Column(type="string", name="att_date", length=20, nullable=true)
     * @var string
     */
    private $date;

    /**
     * @ORM\Column(type="integer", name="att_integer", nullable=true)
     * @var integer
     */
    private $integer;

    /**
     * @ORM\Column(type="text", name="att_object", nullable=true);
     * @var string
     */
    private $object;


    public function getName()
    {
        return $this->name;
    }

    public function setName($val)
    {
        $this->name = $val;
    }

    public function getString()
    {
        return $this->string;
    }

    public function setString($val)
    {
        $this->string = $val;
    }

    public function getInteger()
    {
        return $this->integer;
    }

    public function setInteger($val)
    {
        $this->integer = $val;
    }

    public function getText()
    {
        return $this->text;
    }

    public function setText($val)
    {
        $this->text = $val;
    }

    public function getDate()
    {
        $dateTime = new DateTimeObject();
        $dateTime->fromTimestamp($this->date);
        return $dateTime;
    }

    public function setDate(DateTimeObject $date)
    {
        $this->date = $date->toTimestamp();
    }

    public function getObject()
    {
        $configuration = new AgentRemoteConfigurationObject();
        $configuration->fromJSON($this->object);
        return $configuration;
    }

    public function setObject(AgentRemoteConfigurationObject $configurationObject)
    {
        $this->object = $configurationObject->toJSON();
    }

    public function getArrayCopy()
    {
        return get_object_vars($this);
    }

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function toString()
    {
        $string           = 'ID:                       ' . $this->id . PHP_EOL;
        $string = $string . 'String:                   ' . $this->string . PHP_EOL;
        $string = $string . 'Text:                     ' . $this->text . PHP_EOL;
        $string = $string . 'Integer:                  ' . $this->integer . PHP_EOL;
        $string = $string . 'Date:                     ' . PHP_EOL . $this->getCreated()->toString() . PHP_EOL;
        $string = $string . 'Object:                   ' . PHP_EOL . $this->getObject()->toString() . PHP_EOL;
        $string = $string . 'Owner:                    ' . $this->owner . PHP_EOL;
        return $string;
    }

    public abstract function setOwner($owner);

    public abstract function getOwner();
}
